Skip to content

feat: add matched-cashflow DCA benchmark and SMA regime evaluator - #822

Merged
Pigbibi merged 2 commits into
mainfrom
feat/benchmark-dca-and-sma-regime
Nov 28, 2026
Merged

Pigbibi merged 2 commits into
mainfrom
feat/benchmark-dca-and-sma-regime

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

AI assistance

Antigravity AI assistant authored the offline matched-cashflow DCA benchmark and SMA hysteresis regime module plus unit tests.

What changed

  • Added pure-offline src/quant_platform_kit/risk/benchmark_dca_and_regime.py and re-exported its symbols from src/quant_platform_kit/risk/__init__.py:
    • evaluate_matched_cashflow_dca_benchmark: compares realized portfolio equity against matched external cash-flow passive DCA (SPY / QQQ / arbitrary benchmark symbols) with configurable one-way cost in bps.
    • evaluate_sma_hysteresis_regime: causal SMA ± hysteresis_band regime switch that strictly enforces 0 <= risk_off_multiplier <= risk_on_multiplier <= 1.0 and fails closed on insufficient history or invalid prices.
  • Added unit tests in tests/test_benchmark_dca_and_regime.py.

How verified

  • uv run pytest tests/test_benchmark_dca_and_regime.py tests/test_twr_capital_ladder.py -q
  • uv run ruff check src/quant_platform_kit/risk/benchmark_dca_and_regime.py src/quant_platform_kit/risk/__init__.py tests/test_benchmark_dca_and_regime.py

Why

Provides standardized offline evaluators so pilot/paper reports can measure exact alpha against matched-cashflow index DCA benchmarks and apply a bounded <= 1.0 L4 regime filter without touching broker or order paths.

Risk

Low risk: strictly offline, pure computation module under quant_platform_kit.risk with no broker calls, network I/O, or runtime side effects.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T20:26:19.215647Z 30b0297 Manual request
🔒 Security Review ✅ Completed 2026-11-28T20:27:09.672873Z 30b0297 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed03133d6a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Pigbibi

Pigbibi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 30b02977f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 30b02977f1

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@qsl-gemini-reviewer

Copy link
Copy Markdown

AI Code Review (gemini / gemini-4-neon)

The new offline DCA benchmark and SMA hysteresis regime module is clean, self-contained, and free of security or architecture boundary issues, but has two medium-severity input-handling bugs: SmaHysteresisRegimeConfig allows non-integer sma_window values that later raise TypeError during slicing, and strict (int, float) checks reject NumPy integer/float32 scalars causing valid series to silently fail closed.

Reviewed commit: 30b02977f1 · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] src/quant_platform_kit/risk/benchmark_dca_and_regime.py: SmaHysteresisRegimeConfig.post_init checks isinstance(self.sma_window, bool) or self.sma_window < 2 without verifying isinstance(self.sma_window, int) (or numbers.Integral). A float such as 200.0 or 5.5 passes validation despite the error message saying sma_window must be an integer >= 2, and later crashes with TypeError when slicing closes[-cfg.sma_window :] in evaluate_sma_hysteresis_regime.
  • [MEDIUM] src/quant_platform_kit/risk/benchmark_dca_and_regime.py: _finite_number and evaluate_sma_hysteresis_regime use isinstance(..., (int, float)), which rejects NumPy float32 and integer (np.int64, np.int32) scalars even though NumPy/Pandas are core stack dependencies. In evaluate_sma_hysteresis_regime, passing a valid float32 or int64 NumPy/Pandas close series silently fails closed with INVALID_PRICE_FAIL_CLOSED instead of evaluating the regime. Use numbers.Real (while still excluding bool).
  • [LOW] src/quant_platform_kit/risk/benchmark_dca_and_regime.py: evaluate_matched_cashflow_dca_benchmark normalizes benchmark_symbols with .strip().upper() while _simulate_single_benchmark_dca performs an unnormalized key lookup on obs.benchmark_prices_usd, causing valid lowercase keys to fail with missing benchmark price. Also, rejecting bare str for benchmark_symbols would prevent accidental character-by-character iteration (e.g., 'SPY' -> 'S', 'P', 'Y').
  • [LOW] tests/test_benchmark_dca_and_regime.py: Add unit tests covering beats_all_benchmarks is False, non-positive/inf/bool values in evaluate_sma_hysteresis_regime, cost_bps_oneway upper/lower bounds, and SmaHysteresisRegimeConfig validation branches (sma_window non-int or < 2, hysteresis_band bounds, risk_off_multiplier > risk_on_multiplier).

@Pigbibi Pigbibi added the agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation label Nov 28, 2026
@Pigbibi
Pigbibi merged commit 67dc440 into main Nov 28, 2026
15 of 16 checks passed
@Pigbibi
Pigbibi deleted the feat/benchmark-dca-and-sma-regime branch November 28, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant